<?php
    set_time_limit(0);

    $provider = $_POST['provider'];
    $login = $_POST['login'];
    $passwd = $_POST['passwd'];

    $inviter = new OpenInviter();
    $oi_services = $inviter->getPlugins();
    if (isset($oi_services['email'][$provider])) $plugType = 'email';
    elseif (isset($oi_services['social'][$provider])) $plugType = 'social';
    else $plugType='';

    if($provider != null && $login != null && $passwd != null){
        $inviter->startPlugin($provider);
        $inviter->login($login, $passwd);
        $contacts = $inviter->getMyContacts();
        if(is_array($contacts)) {
            $people = array();
            $nbmembers = 0;		// Utilisateurs connus
			$nbnonmembers = 0;	// Utilisateurs inconnus
			$nbtotal = 0;		// Utilisateurs total
            foreach($contacts as $mail => $contact) {
				if($mail != $_SESSION['user']['email']) { 
					$people[$nbtotal]['name'] = $contact;
					$people[$nbtotal]['mail'] = $mail;
					$people[$nbtotal]['id'] = $nbtotal;
					if($user = User::existMail($mail)) {
						$people[$nbtotal]['user'] = $user;
						if($_SESSION['user']->isFriend($user['id'])) {
							$people[$nbtotal]['status'] = 2;
						} else {
							$people[$nbtotal]['status'] = 1;
						}
						$nbmembers++;
					} else {
						$people[$nbtotal]['status'] = 0;
						$nbnonmembers++;
					}
					$nbtotal++;
				}
    		}
	    }
    }
?>